<?php

function validate_login_name($login_name) {
	if(strlen($login_name) > 2 && strlen($login_name <= 20)) {
		mysql_real_escape_string($login_name);
		$sql = "SELECT COUNT(*) as count FROM users WHERE username=\"$login_name\"";
		$result = mysql_query($sql);
		$row = mysql_fetch_assoc($result);
		
		if($row['count'] > 0) {
			return 0;
		} else {
			return 1;
		}
	} else {
		return 0;
	}
}

function validate_password($pwd1, $pwd2) {
	if(strlen($pwd1) > 5 && strlen($pwd1) < 25) {
		if($pwd1 == $pwd2) {
			return 1;
		} else {
			return 0;	
		}
	} else {
		return 0;
	}
}

function validate_email($email) {
	if(preg_match("/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i", $email)) {
		return 1;
	} else {
		return 0;
	}
}
 
?>
